<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>后台管理-登录</title>
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="__ADMIN_PATH__/component/pear/css/pear.css" />
		<link rel="stylesheet" href="__ADMIN_PATH__/admin/css/other/login.css" />
		<script type="text/javascript">
	        if(window != top){
	            top.location.href = location.href;
	        }
	    </script>
	</head>
    <!-- 代 码 结 构 -->
	<body background="__ADMIN_PATH__/admin/images/background.svg" style="background-size: cover;">
		<form class="layui-form" action="javascript:void(0);">
			<div class="layui-form-item">
				<img class="logo" src="__ADMIN_PATH__/admin/images/logo.png" />
				<div class="title">摩小妹系统</div>
				<!--<div class="desc">
					明 湖 区 最 具 影 响 力 的 设 计 规 范 之 一
				</div>-->
			</div>
			<div class="layui-form-item">
				<input type="text" name="username" placeholder="账 号" lay-verify="" hover class="layui-input"  />
			</div>
			<div class="layui-form-item">
				<input type="password" name="password" placeholder="密 码" lay-verify="" hover class="layui-input"  />
			</div>
			<div class="layui-form-item">
				<input type="text" name="captcha" placeholder="验证码"  hover  lay-verify="" class="code layui-input"  />
			</div>
			<div class="layui-form-item">
				<img id="img_verify" url="{:url('Publics/captcha')}" src="{:url('Publics/captcha')}" style="width: 100%;" title="点击切换" />
			</div>
			
			<!--<div class="layui-form-item">
				<input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
			</div>-->

			<div class="layui-form-item">
				<button type="button" class="pear-btn pear-btn-success login" id="login" lay-submit lay-filter="login">
					登 录
				</button>
			</div>
		</form>
		<!-- 资 源 引 入 -->
		<script src="__ADMIN_PATH__/component/layui/layui.js"></script>
		<script src="__ADMIN_PATH__/component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'button', 'popup', 'jquery', 'loading'], function() {
				var form = layui.form;
				var button = layui.button;
				var popup = layui.popup;
				let $ = layui.jquery;
				let loading = layui.loading;
				/**
	             * 刷新验证码
	             */
				$('#img_verify').click(function(){
					$(this).attr('src',$(this).attr('url')+'?'+Math.random());
	            });

                // 登 录 提 交
				form.on('submit(login)', function(data) {
					$.ajax({
						url:"{:url('Publics/login')}",
						type:"POST",
						dataType:"JSON",
						data:data.field,
						beforeSend: function () {
							loading.Load(1, "");
	                    },
	                    complete: function () {
	                    	loading.loadRemove();
	                    },
	                    success:function(res)
	                    {
	                    	//再次刷新验证码
	                    	if(data.field.username != '' && data.field.password != '' && data.field.captcha != '')
	                        {
	                            $('#img_verify').click();
	                        }
	                        if(res.code == 0)
	                        {
	                        	//正常业务
	                        	popup.success(res.msg, function(){
	                        		window.location = "{:url('Index/index')}";
	                        	});
	                        }else
	                        {
	                        	//业务异常
	                        	popup.warning(res.msg);
	                        }
	                    },
	                    error:function()
	                    {
	                    	loading.loadRemove();
	                    	popup.failure('服务器错误');
	                    }
	                });
					return false;
				});
			});
			document.onkeydown = function (event) {
                var e = event || window.event;
                if (e && e.keyCode == 13) { //回车键的键值为13
                    document.getElementById('login').click();
                }
            };


		</script>
	</body>
</html>